{% load i18n freeadmin %}
<form data-dojo-type="dijit.form.Form" encType="multipart/form-data" id="dialogForm_{{ model_name }}">
<script type="dojo/method" data-dojo-event="submitForm" data-dojo-args="form,e,conf">
     doSubmit({
        form: form,
        event: e,
        url: '{{ request.path }}{% if inline %}?inline=true{% endif %}',
        confirm: conf
     });
</script>
{% block post_form %}
<script type="dojo/event" data-dojo-event="onSubmit" data-dojo-args="e">
this.submitForm(this, e);
</script>
{% endblock %}
{% if inline and saved %}<span class="saved">{% trans "Your changes have been successfully updated!" %}</span>{% endif %}
<table class="form">
    {% block formset_top %}
    {% include "freeadmin/generic_model_inline.html" with position='top' %}
    {% endblock %}
    {% block form %}
    {% csrf_token %}
    {% admin_form form %}
    {% endblock %}
    {% block formset_bottom %}
    {% include "freeadmin/generic_model_inline.html" with position='bottom' %}
    {% endblock %}
    {% block buttons %}
    <tr>
        <td colspan="2">
            <button id="btn_{{ model_name }}_Ok" class="submitform" data-dojo-type="dijit.form.Button" data-dojo-props="type:'submit'">
                {% if extra_js %}
                <script type="dojo/method">
                        {{ extra_js }}
                </script>
                {% endif %}
                {% block oklabel %}
                {% if inline %}
                {% trans "Save" %}
                {% else %}
                {% trans "OK" %}
                {% endif %}
                {% endblock %}
            </button>
            {% if not inline %}
            <button id="btn_{{ model_name}}_Cancel" data-dojo-type="dijit.form.Button" class="cancelform">
                {% trans "Cancel" %}
                <script type="dojo/method" data-dojo-event="onClick" data-dojo-args="evt">
                    cancelDialog(this);
                </script>
            </button>
            {% endif %}
            {% if deletable %}
            <button id="btn_{{ model_name}}_Delete" data-dojo-type="dijit.form.Button" >
                <script type="dojo/event" data-dojo-event="onClick" data-dojo-args="e">
		var button = this;
		require([
		"dojo/query",
		"dojo/request/xhr",
		"dijit/registry"
		], function(query, xhr, registry) {
                    try {
                        var form = getForm(button);
                        query('input[type=button],input[type=submit]', form.domNode).forEach(
                            function(inputElem){
                                 registry.getEnclosingWidget(inputElem).set('disabled',true);
                             }
                          );
                    } catch(err) {}

                    var rnode = getDialog(button);
                    if(!rnode) rnode = registry.byId("edit_dialog");
                    xhr.get('{{ delete_url }}', {
                        handleAs: 'text'
			}).then(function(data) {
			    rnode.set('content', data);
                        });
                });
                </script>{% trans "Delete" %}</button>
            {% endif %}
            {% with form.advanced_fields as advfields %}
            {% include "freeadmin/advanced_btn.html" %}
            {% endwith %}
            {% block buttons_extra %}
            {% endblock %}
            {% for btn in hook_buttons %}
              <button id="btn_{{ model_name }}_{{ btn.name }}" data-dojo-type="dijit.form.Button" type="button">
                  {{ btn.verbose_name }}
              <script type="dojo/method" data-dojo-event="onClick" data-dojo-args="evt">
                  {{ btn.onclick|safe }}
              </script>
              </button>
            {% endfor %}
        </td>
    </tr>
    {% endblock %}
</table>
</form>
